package org.example.demo9;

import lombok.SneakyThrows;

import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * FutureTask
 * @author Gong.Yang
 */
public class Demo9 {
    @SneakyThrows
    public static void main(String[] args) {

        FutureTask<Integer> task = new FutureTask<>(() -> {
            TimeUnit.SECONDS.sleep(1);
            return 1;
        });

        Thread thread = new Thread(task);
        thread.start();

        System.out.println("before");
        Integer integer = task.get(); //阻塞到线程结束
        System.out.println("after res:"+integer);
    }
}
